{ "cells": [ { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied (use --upgrade to upgrade): ivisual in /home/dblank/.local/lib/python3.4/site-packages\r\n" ] } ], "source": [ "!pip3 install ivisual --user" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "require.undef(\"nbextensions/glow.1.0.min\");" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "require.undef(\"nbextensions/jquery-ui.custom.min\");" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "require.undef(\"nbextensions/glow.1.1.min\");" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "require.undef(\"nbextensions/glowcomm\");" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "require([\"nbextensions/glowcomm\"], function(){console.log(\"glowcomm loaded\");})" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from ivisual import *" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "window.__context = { glowscript_container: $(\"#glowscript\").removeAttr(\"id\")}" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "Right button drag to rotate \"camera\" to view scene.\n", " On a one-button mouse, right is Command + mouse.\n", "Middle button to drag up or down to zoom in or out.\n", " On a two-button mouse, middle is left + right.\n", " On a one-button mouse, middle is Option + mouse.\n", "\n" ] }, { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "scene = canvas('Ball in Box')\n", "print(\"\"\"\n", "Right button drag to rotate \"camera\" to view scene.\n", " On a one-button mouse, right is Command + mouse.\n", "Middle button to drag up or down to zoom in or out.\n", " On a two-button mouse, middle is left + right.\n", " On a one-button mouse, middle is Option + mouse.\n", "\"\"\")\n", "\n", "side = 4.0\n", "thk = 0.3\n", "s2 = 2*side - thk\n", "s3 = 2*side + thk\n", "wallR = box (pos=( side, 0, 0), size=(thk, s2, s3), color = color.red)\n", "wallL = box (pos=(-side, 0, 0), size=(thk, s2, s3), color = color.red)\n", "wallB = box (pos=(0, -side, 0), size=(s3, thk, s3), color = color.blue)\n", "wallT = box (pos=(0, side, 0), size=(s3, thk, s3), color = color.blue)\n", "wallBK = box(pos=(0, 0, -side), size=(s2, s2, thk), color = (0.7,0.7,0.7))\n", "\n", "#ball = sphere (color = color.green, radius = 0.4)\n", "ball = sphere (color = color.green, radius = 0.4, make_trail=True, interval=5, retain=30)\n", "#ball = cone (color = color.green, radius = 0.4, make_trail=True, interval=5, retain=30)\n", "ball.mass = 1.0\n", "ball.p = vector (-0.15, -0.23, +0.27)\n", "\n", "side = side - thk*0.5 - ball.radius\n", "\n", "display(scene)\n", "\n", "dt = 0.5\n", "t=0.0\n", "while t < 2000:\n", " rate(100)\n", " t = t + dt\n", " ball.pos = ball.pos + (ball.p/ball.mass)*dt\n", " if not (side > ball.x > -side):\n", " ball.p.x = -ball.p.x\n", " if not (side > ball.y > -side):\n", " ball.p.y = -ball.p.y\n", " if not (side > ball.z > -side):\n", " ball.p.z = -ball.p.z" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.4.3" } }, "nbformat": 4, "nbformat_minor": 0 }